package com.zfzs.post.controller;

import com.zfzs.post.aop.log.Log;
import com.zfzs.post.common.bean.ResponseResult;
import com.zfzs.post.model.dto.AppPayDTO;
import com.zfzs.post.service.OrderService;
import com.zfzs.post.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * 支付和支付回调接口
 *
 * @author ck
 * @date 2019/10/8 17:43
 */
@Slf4j
@RestController
@RequestMapping("pay/")
public class PayController {

    @Autowired
    private OrderService orderService;

    /**
     * 支付宝APP支付
     */
    @Log("支付宝APP支付")
    @PostMapping(value = "ali_app_pay")
    public ResponseResult getGoodsList(@Validated @RequestBody AppPayDTO dto) {
        String res = orderService.appPay(dto);
        Map<String, Object> map = new HashMap<>();
        map.put("res", res);
        return ResponseResult.ok("支付成功", map);
    }

    /**
     * 支付宝支付回调
     */
    @Log("支付宝支付回调")
    @PostMapping(value = "ali_app_callback")
    public String aliAppCallback(HttpServletRequest requests) {
        return orderService.aliAppCallback(requests);
    }

}
